package leetcode.code2001;

import java.util.HashMap;
import java.util.Map;

import leetcode.IDebug;

public class Solution implements IDebug {

	public long interchangeableRectangles(int[][] rectangles) {
		Map<String, Integer> hash = new HashMap<>();
		for (int i = 0; i < rectangles.length; i++) {
			int[] rect = rectangles[i];
			int w = rect[0], h = rect[1];
			int gcd = this.gcd(w, h);
			String key = w / gcd + "-" + h / gcd;
			hash.put(key, hash.getOrDefault(key, 0) + 1);
		}
		long ans = 0;
		for (int value : hash.values()) {
			ans += (long) value * (value - 1) / 2;
		}
		return ans;
	}

	private int gcd(int a, int b) {
		// TODO Auto-generated method stub
		return b == 0 ? a : gcd(b, a % b);
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
